#!/bin/bash

sockfile=/tmp/{{=project}}.sock
projectdir={{=project_dir}}
logfile={{=log_dir}}/{{=project}}.log


if [ $1 = start ];then
 psid=`ps aux|grep "uwsgi"|grep -v "grep"|wc -l`
 if [ $psid -gt 2 ];then
   echo "uwsgi is running!"
   exit 0
 else
   uwsgi -s $sockfile --chdir $projectdir -w wsgi_handler -p 10 -M -t 120 -T -C -d $logfile
 fi
 echo "Start uwsgi service [OK]"
elif [ $1 = stop ];then
 killall -9 uwsgi
 echo "Stop uwsgi service [OK]"
elif [ $1 = restart ];then
 killall -9 uwsgi
 uwsgi -s $sockfile --chdir $projectdir -w wsgi_handler -p 10 -M -t 120 -T -C -d $logfile
 echo "Restart uwsgi service [OK]"
else
 echo "Usages: sh start.sh [start|stop|restart]"
fi
